﻿using System;
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;

public class GameManager : MonoBehaviour
{
    private static GameManager _instance;

    public static GameManager Instance
    {
        get { return _instance; }
    }
    public int level = 1;//当前关卡
    public int food = 100;
    private bool isMove = true;
    public List<Enemy> enemyList = new List<Enemy>();
    private Text foodText;

    void Awake()
    {
        _instance = this;
        InitGame();
    }

    void InitGame()
    {
        foodText = GameObject.FindGameObjectWithTag("UI").GetComponent<Text>();
        UpdateFoodText();
    }

    void UpdateFoodText()
    {
        foodText.text = "Food:" + food;
    }

    public void ReduceFood(int count)
    {
        food -= count;
        UpdateFoodText();
        if (food <= 0)
        {
            foodText.rectTransform.localPosition = new Vector2(-1.7f, 20f);
            foodText.fontSize = 30;
            foodText.text = "GAME OVER";
        }
    }

    public void AddFood(int count)
    {
        food += count;
        UpdateFoodText();
    }

    public void OnPlayerMove()
    {
        if (isMove)
        {
            isMove = false;
        }
        else
        {
            foreach (var enemy in enemyList)
            {
                enemy.EnemyMove();
            }
            isMove = true;
        }
    }
}
